package library.commands;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import library.domain.Book;
import library.domain.User;
import library.service.BookService;

public class UploadCommand extends Command {

    public UploadCommand(ObjectInputStream input, ObjectOutputStream output, Socket socket) {
        super(input, output, socket);
    }

    @Override
    public void execute() throws Exception {
        User user = CommandManager.getInstance().getUserForSocket(socket);
        if (user.getId() == null || user.getId() == -1) {
            return;
        }
        Book b = (Book) input.readObject();

        BookService bookService = serviceLocator.getService(BookService.class);
        bookService.newBook(b);
    }
}
